function hrefBack() {
    history.go(-1);
}

function decodeQuery(){
    var search = decodeURI(document.location.search);
    //?id=3&name=张三===>replace==>id=3&name=张三===>split("&")==>["id=3","name=张三"]==>reduce()===>
    //
    return search.replace(/(^\?)/, '').split('&').reduce(function(result, item){
        //"id=3"===>split===>["id","3"]

        //"name=张三"===>split==>["name","张三"]
        values = item.split('=');
        //result={}
        //result["id"]=3
        //result={"id":"3"}

        //result["name"]="张三"
        // result={"id":3,"name":"张三"}
        result[values[0]] = values[1];
        return result; //result={"id":3,"name":"张三"}
    }, {});
}

$(document).ready(function(){
    //{"id":"3"}
    var queryData = decodeQuery()
    var houseId = queryData["id"]

    //获取该房屋的详情信息
    $.get("/api/v1.0/houses/"+houseId,function(resp){
        if (resp.errno=="0") {
            $(".swiper-container").html(template("house-image-tmpl", {
                "img_urls": resp.data.house.img_urls,
                "price": resp.data.house.price
            }))

            $(".detail-con").html(template("house_detail_tmpl", {"house": resp.data.house}))
            // resp.data.user_id为访问页面用户,resp.data.house.user_id为房东
            if (resp.data.user_id != resp.data.house.user_id) {
                //显示【即刻预订按钮】 $(".book-house").attr("href", "/booking.html?hid=" + resp.data.house.hid)
                $(".book-house").show()
            }

            var mySwiper = new Swiper('.swiper-container', {
                loop: true,
                autoplay: 2000,
                autoplayDisableOnInteraction: false,
                pagination: '.swiper-pagination',
                paginationType: 'fraction'
            })
        }
    })

})